<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" session="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>管理</title>

    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/js/global.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        .main h5 a {
            position: absolute;
            right: 20px;
            font-size: 14px;
            bottom: 0px;
            display: inline-block;
            padding: 5px;
        }

        .table_list tbody tr {
            height: 35px;
            text-align: center;
        }
        .butt{
        	width: 100px;
		}
		.left ul li{
			
			*line-height:40px;
			
			*padding-left:20px;
		}
		
		.left ul li a, .left ul li a:hover{
			*color:#fff;
		}
		.list-tab li{
			*+padding:0px 10px 10px;
		}
		.wrapper{
			*margin-left:270px;
		}
    </style>
</head>
<body view="menu-item-4142">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
 	<div class="wrapper">

	    <div class="jqGrid_wrapper">
	        <div id="jqGrid_operation" class="jg-grid">
	            <h1></h1>
	            <div class="jqGrid_operation" id="action"></div>
	        </div>
	        <table id="jqGrid"></table>
	        <div id="jqGrid_paper"></div>
	    </div>
	</div>
</div>
<script>
	var ifreply = false;
    $(document).ready(
            function () {
            	/* $.ajax({
                    type: "POST",
                    async: false,
                    url: '/admin/auth_buttons.action',
                    data: "url=" + window.location.pathname,
                    success: function (data) {
                        data = eval("(" + data + ")");
                        for (var i in data) {
                            var action = data[i].mName;
                            switch (action) {
                                case "报修删除":
                                    $("#action").append("<a id=\"del\"><i class=\"glyphicon glyphicon-trash\"></i>删除</a>");
                                    $("#del").click(function () {
                                        var sels = jQuery("#jqGrid").jqGrid('getGridParam', 'selarrrow');
                                        if (sels == "") {
                                            layer.alert("请选择要删除的维修记录", {
                                                icon: 6,
                                                closeBtn: false
                                            });
                                        } else {
                                            layer.confirm('确认删除所选择的维修记录', function (index) {
                                                $.post("${pageContext.request.contextPath}/admin/fix_delete.action", {
                                                    "ids": sels.toString()
                                                }, function (result) {
                                                    result = eval("(" + result + ")");
                                                    layer.alert(result.msg);
                                                    refreshGrid();
                                                });
                                                layer.close(index);
                                            });
                                        }
                                    });
                                    break;
                                case "报修回复":
                                	 ifreply = true;
                                	 break;
                            }
                        }
                    }
                }); */
                $.jgrid.defaults.styleUI = "Bootstrap";
	                $("#jqGrid").jqGrid({
	                      url: "${pageContext.request.contextPath}/admin/funcMain_page.action",
	                      mtype: 'POST',
	                      datatype: "json",
	                      height: 350,
	                      autowidth: true,
	                      shrinkToFit: true,
	                      rowNum: 10,
	                      rowList: [10, 20, 30],
	                      colNames: ['序号','应用名称','申请时间', '审核时间', '审核人', '小区总数',
	                          '已开通小区数', '详情', '操作'],
	                      colModel: [{
	                          name: "SID",
	                          index: "SID",
	                          key: true,
	                          hidden: true
	                      }, {
	                          name: 'CNAME',
	                          index: 'CNAME',
	                          width: 60
	                      }, {
	                          name: 'APPLY_TIME',
	                          index: 'APPLY_TIME',
	                          width: 80
	                      }, {
	                          name: 'AUDIT_TIME',
	                          index: 'AUDIT_TIME',
	                          width: 90
	                      }, {
	                          name: "CNAME",
	                          index: "CNAME",
	                          width: 80
	                      }, {
	                          name: 'COMMUNITY_COUNT',
	                          index: 'COMMUNITY_COUNT',
	                          width: 40
	                      },{
	                          name: 'COMMUNITY_OPEN_COUNT',
	                          index: 'COMMUNITY_OPEN_COUNT',
	                          width: 60
	                      },{
	                          name: "CNAME",
	                          index: "CNAME",
	                          width: 60
	                      },{
                              name: 'CNAME',
                              index: 'CNAME',
                              width: 100,
                              formatter: function (cellvalue, options, rawObject) {
                            	  if(cellvalue=='-1' || !cellvalue){
		                              	return '';
		                          }else{
		                               	return '<input type="button" style="padding: 2px 10px" class="btn btn-success" value="申请" onclick="apply('+rawObject.SID+')"/>'+'<input type="button" style="padding: 2px 10px;margin-left:5px" class="btn btn-success" value="详情" onclick="view('+rawObject.SID+')"/>';
			                      }
                           	  }
                          }],
	                      sortname: 't.sid',
	                      sortorder:'desc',
	                      rownumbers: true,
	                      jsonReader: {
	                          root: 'rows',
	                          page: "page",
	                          total: 'total',
	                          records: "records",
	                          repeatitems: false
	                      },
	                      pager: "#jqGrid_paper",
	                      viewrecords: true,
	                      multiselect: true,
	                      hidegrid: false,
	                      loadComplete: function(){
	                    		var re_records = Number($("#jqGrid").getGridParam('records'));
	                    		var page = Number($("#jqGrid").getGridParam('page'));
	                    		var rows=Number($("#jqGrid").getGridParam('rowNum'));
	                    		var num = re_records-(page-1)*rows;
	                    		if(num < rows)
	                    		{
	                    			for(var i=num;i<rows;i++){
	                    				$("#jqGrid").jqGrid("addRowData",(i+1),
	                            				{ "SID":"","STATUS":"-1"}
	                    				,"");
	                    			}
	                    			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
	                    		}
	                    	}
	                  });
                
                <!--查询-->
                jQuery("#query").click(query);
                jQuery("#resetForm").click(resetForm);
            });

    <!--刷新jqGrid表格数据-->
    function refreshGrid() {
        $("#jqGrid").trigger("reloadGrid");
    }
    function resetForm() {
        location.reload();
        return false;
    }
    function apply(sid){
    	layer.open({
            type: 2,
            title: '<strong>申请</strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['600px', '580px'],
            content: '${pageContext.request.contextPath}/admin/funcMain_applyView.action?sid='
            + sid,
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                
                var communityids='';
                var alipayIds='';
                var sid=$("#layui-layer-iframe" + index).contents().find("#sid").val();
                $("#layui-layer-iframe" + index).contents().find("input[name='communityid']:checkbox:checked").each(function(){ //选中的小区
                	var communityid = $(this).val();
                	var cname=$(this).attr("cname");
                	var alipayId = $("#layui-layer-iframe" + index).contents().find("#alipay_"+communityid).val();
                	if(alipayId==null||alipayId==''){
                		layer.alert('小区：'+cname+"，未选择对应的支付宝账号", {
                            icon: 6,
                            closeBtn: false
                        });
                		return;
                	}
                	communityids+=communityid+",";
                	alipayIds+=alipayId+",";
                	
                });
                if(communityids==''){
                	layer.alert("请勾选至少一个社区", {
                        icon: 6,
                        closeBtn: false
                    });
            		return;
                }
                $.post("${pageContext.request.contextPath}/admin/funcMain_apply.action",'communityids='+communityids+'&alipayIds='+alipayIds+'&sid='+sid,function(data){
                     if (data.code == 1) {
                         layer.alert(data.msg, function () {
                             layer.closeAll();
                             refreshGrid();
                         });
                     } else {
                         layer.alert(data.msg);
                     }
                  },'json');
            }
        });
    }
    
    function view(sid){
    	layer.open({
            type: 2,
            title: '<strong></strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['1000px', '580px'],
            content: '${pageContext.request.contextPath}/admin/funcMain_viewDetail.action?sid='
            + sid,
            btn: ['关闭'],
            yes: function (index, layero) {
                layer.close(index)
            }
        });
    }

    function query() {
        var agtCode = $("#agtCode").val();
        var communityId = $("#communityId").val();
        var areaCode;
        if('${userRole}' != 5 && '${userRole}' != 6){
	        var selects=document.getElementsByName('location');
	        areaCode = selects[0].value;
		}
        var userName = $("#userName").val();
        var userTel = $("#userTel").val();
        var replytype = $("#replytype").val();
        var status = $("#status").val();
        $("#jqGrid").jqGrid('setGridParam', {
            url: "${pageContext.request.contextPath}/admin/fix_page.action",
            postData: {
                'agtCode': agtCode,
                'communityId': communityId,
                'areaCode': areaCode,
                'userName': userName,
                'userTel': userTel,
                'replytype': replytype,
                'status': status
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入*/
        return false;
    };
		window.onload=function(){
		function BrowserType(){
			//获取浏览器的userAgent代理号；
			var userAgent=navigator.userAgent;
			
			//判断是否是Opera浏览器
			var isOpera=userAgent.indexOf("Opera")>-1;
			//判断是否是IE浏览器
			var isIE=userAgent.indexOf("compatible")>-1 && userAgent.indexOf("MSIE")>-1 && !isOpera;
			//判断是否是IE7浏览器
			if(isIE){
				var relIE=new RegExp("MSIE(\\d+\\.\\d+);");
				
				relIE.test(userAgent);
				var arr=userAgent.split(";")
				var flEVersion=arr[1].indexOf("7");
				if(flEVersion>-1){
					$tr=$("thead tr th");
					var t=$("tbody tr")[2];
					
					var d=t.getElementsByTagName("td");
					d[0].style.width=10+"px";
					$td=$("tbody tr td");
					var len=$tr.length;
					for(var i=0;i<len;i++){
						$tr[i].style.width=30+"px";
						
						$td[i].style.width=30+"px";
						
					};
				}
			}
		};
		BrowserType();
	};
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length >>> 0;
    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;
    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  }
};
//     function haveReplyView(){
//         layer.open({
//             type: 2,
//             title: ['回复', 'font-weight:bold'],
//             shadeClose: true, //点击遮罩关闭层
//             area: ['800px', '430px'],
//             scrollbar: false,
//             content: '${pageContext.request.contextPath}/admin/fix_replyView.action',
//             btn: ['确定'],
//             yes: function (index, layero) {
//             	layer.close(index);
//             }
//         });
//     }
</script>
</body>
</html>
